<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\KnowledgeGuideTag;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class KnowledgeGuideTagController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new KnowledgeGuideTag(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('tag');
            $grid->column('name');
            $grid->column('week');
            $grid->column('week_s');
            $grid->column('mother_num');
            $grid->column('father_num');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new KnowledgeGuideTag(), function (Show $show) {
            $show->field('id');
            $show->field('tag');
            $show->field('name');
            $show->field('week');
            $show->field('week_s');
            $show->field('mother_num');
            $show->field('father_num');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(\App\Models\KnowledgeGuideTag::with(['titles','contents']), function (Form $form) {


            $form->tab('基础字段', function (Form $form) {
                $form->text('tag');
                $form->text('name');
                $form->text('week');
                $form->text('week_s');
                $form->text('mother_num');
                $form->text('father_num');
            })->tab('人物内容', function (Form $form){
                $form->hasMany('titles', function (Form\NestedForm $form) {
                    $form->text('tag','标题');
                    $form->textarea('content','内容');

                })->label('人物内容');
            })->tab('指南内容', function (Form $form){
                $form->hasMany('contents', function (Form\NestedForm $form){
                    $form->text('title','标题');
                    $form->textarea('content','内容');
                    $form->text('tag');
                    $form->number('sort','排序');
                })->label('指南内容');
            });
         });
    }
}
